package com.lcm.weam.controller.sys;

import com.lcm.weam.entity.resp.Result;
import com.lcm.weam.entity.resp.ResultCode;
import com.lcm.weam.entity.sys.Permission;
import com.lcm.weam.service.sys.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * permission的接口前端不调用
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/sys/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping(value = "/addPermission", method = RequestMethod.PUT)
    public Result addPermission(@RequestBody Permission permission) {
        permissionService.addPermission(permission);
        return new Result(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/updatePermission/{pid}", method = RequestMethod.POST)
    public Result updatePermission(@RequestBody Permission permission, @PathVariable Integer pid) {
        permissionService.updatePermission(permission, pid);
        return new Result(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/selectAllPermission", method = RequestMethod.GET)
    public Result selectAllPermission() {
        List<Permission> permissions = permissionService.selectAllPermission();
        return new Result(ResultCode.SUCCESS, permissions);
    }

    //删除权限还要把映射表中的引用删除
    @RequestMapping(value = "/deletePermission/{pid}", method = RequestMethod.POST)
    public Result deletePermission(@PathVariable Integer pid){
        permissionService.deletePermission(pid);
        return new Result(ResultCode.SUCCESS);
    }

    
}
